##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 配置 MSVC 的 RelWithDebInfo 模式
function(my_config_msvc_relwithdebinfo target_name)
    if(NOT TARGET ${target_name})
        message(WARNING "Target ${target_name} 不存在")
        return()
    endif()
    # 确保只在 MSVC 编译器下执行
    if(NOT WIN32)
        message(STATUS "[my_config_msvc_relwithdebinfo] Skip, not in windows")
        return()
    endif()

    set(MY_REL_DEB_OPTS "/utf-8;/EHsc;/Zc:__cplusplus;/permissive-;/Od;/Zi;/DDEBUG;/UNDEBUG")
    list(JOIN MY_REL_DEB_OPTS_CUDA "," MY_REL_DEB_OPTS)
    # 针对 RelWithDebInfo 关闭优化，启用调试宏
    target_compile_options(${target_name} PRIVATE
        # c++ 选项: 禁用优化; 确保生成调试信息; 定义 DEBUG 宏; 取消 NDEBUG 宏
        "$<$<AND:$<CONFIG:RelWithDebInfo>,$<COMPILE_LANGUAGE:CXX>>:${MY_REL_DEB_OPTS}>" # C++: 合并所有选项
        "$<$<AND:$<CONFIG:RelWithDebInfo>,$<COMPILE_LANGUAGE:CUDA>>:-Xcompiler=${MY_REL_DEB_OPTS_CUDA}>" # CUDA: 合并所有选项
    )

    # 确保生成 PDB 文件
    target_link_options(${target_name} PRIVATE
        "$<$<CONFIG:RelWithDebInfo>:/DEBUG>" # 确保生成 PDB 文件
    )

    # 设置运行时库为 Debug 版本（可选，但可能影响 ABI）
    # 如需启用，取消下面的注释
    # set_property(TARGET ${target_name} PROPERTY
    #     MSVC_RUNTIME_LIBRARY "MultiThreadedDebug$<$<CONFIG:Debug>:Debug>"
    # )
endfunction()


##xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx copy project dependent dlls to binary dir, windows
function(my_cp_dlls target)
    if(NOT WIN32)
        message(STATUS "[my_cp_dlls] Skip, not in windows")
        return()
    endif()
    add_custom_command(TARGET ${target} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:${target}> $<TARGET_FILE_DIR:${target}>
        COMMAND_EXPAND_LISTS
        COMMENT "[my_cp_dlls] Copying DLLs to build directory")
endfunction()


##0000000000000000000000000000000000000000000000000000000 copy conan2 runtime
function(my_cp_dlls target)
    # if(NOT WIN32)
    #     message(STATUS "[MY] Skip, not in windows")
    #     return()
    # endif()
    add_custom_command(TARGET ${target} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:${target}> $<TARGET_FILE_DIR:${target}>
        COMMAND_EXPAND_LISTS
        COMMENT "[MY] Copying DLLs to build directory")
endfunction()
